// TestSPView.cpp : implementation file
//

#include "stdafx.h"
#include "GStation.h"
#include "TestSPView.h"
#include "FlyView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestSPView

IMPLEMENT_DYNCREATE(CTestSPView, CFormView)

CTestSPView::CTestSPView()
	: CFormView(CTestSPView::IDD)
{
	//{{AFX_DATA_INIT(CTestSPView)
	m_sdv1 = 0.0;
	m_sdv2 = 0.0;
	m_sdv3 = 0.0;
	//}}AFX_DATA_INIT
}

CTestSPView::~CTestSPView()
{
}

void CTestSPView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestSPView)
	DDX_Text(pDX, IDC_SDV_1, m_sdv1);
	DDX_Text(pDX, IDC_SDV_2, m_sdv2);
	DDX_Text(pDX, IDC_SDV_3, m_sdv3);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestSPView, CFormView)
	//{{AFX_MSG_MAP(CTestSPView)
	ON_BN_CLICKED(IDC_SendSDTestValue, OnSendSDTestValue)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestSPView diagnostics

#ifdef _DEBUG
void CTestSPView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTestSPView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestSPView message handlers

CGStationDoc * CTestSPView::GetDocument()
{
	return (CGStationDoc * )m_pDocument;
}

void CTestSPView::OnSendSDTestValue() 
{
	DWORD time1=GetTickCount();
	UpdateData(true);
	DWORD time2=GetTickCount();
	if(!((time2-time1)>100))
	{
		
		unsigned char *buf,*value;
		buf = (unsigned char *)malloc(sizeof(TiltDiscTstInsData)+2);
		value = buf+2;
		INSHEAD * head = (INSHEAD *)buf;
		*head  = STT_TILTDISC_TST;

		TiltDiscTstInsData text;

		double v1,v2,v3;
		v1 = m_sdv1 ;
		v2 = m_sdv2;
		v3 = m_sdv3 ;
		text.CollectSetAngle = v1;
		text.RollSetAngle = v2;
		text.PitchetAngle = v3;
		
		memcpy(value,&text,sizeof(TiltDiscTstInsData));
		while(doc->cln.OnSendData(buf,sizeof(TiltDiscTstInsData)+2)==false)
		{

		}
		free(buf);
	}
}
